import java.util.Arrays;
import java.util.Stack;

public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minstack;
    public MinStack() {
        stack=new Stack<>();
        minstack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()){
            minstack.push(stack.peek());
        }
        if(stack.peek()<=minstack.peek()){
            minstack.push(stack.peek());
        }
    }

    public void pop() {
        if(stack.peek()==minstack.peek()){
            minstack.pop();
            stack.pop();

        }
        else{ stack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }
}
